local assets =
{
	Asset("ANIM", "anim/torso_dragonfly.zip"),
}

local function OnBlocked(owner, data)
	owner.SoundEmitter:PlaySound("dontstarve/wilson/hit_armour")
	if data.attacker and data.attacker.components.burnable and not data.attacker:HasTag("thorny") then
		data.attacker.components.burnable:Ignite()
	end
end

local function onequip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_body", "torso_dragonfly", "swap_body")

	inst:ListenForEvent("blocked", OnBlocked, owner)
	inst:ListenForEvent("attacked", OnBlocked, owner)

	if owner.components.health then
		owner.components.health.fire_damage_scale = owner.components.health.fire_damage_scale - TUNING.ARMORDRAGONFLY_FIRE_RESIST
	end
end

local function onunequip(inst, owner)
	owner.AnimState:ClearOverrideSymbol("swap_body")

	inst:RemoveEventCallback("blocked", OnBlocked, owner)
	inst:RemoveEventCallback("attacked", OnBlocked, owner)

	if owner.components.health then
		owner.components.health.fire_damage_scale = owner.components.health.fire_damage_scale + TUNING.ARMORDRAGONFLY_FIRE_RESIST
	end
end

local function fn()
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("torso_dragonfly")
	inst.AnimState:SetBuild("torso_dragonfly")
	inst.AnimState:PlayAnimation("anim")

    inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end

	inst:AddComponent("inspectable")
	inst:AddComponent("inventoryitem")

	inst:AddComponent("armor")
	inst.components.armor:InitCondition(TUNING.ARMORDRAGONFLY, TUNING.ARMORDRAGONFLY_ABSORPTION)

	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.BODY
	inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED

	inst.components.equippable:SetOnEquip( onequip )
	inst.components.equippable:SetOnUnequip( onunequip )

	MakeHauntableLaunch(inst)

	return inst
end

return Prefab( "common/inventory/armordragonfly", fn, assets)
